<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>提现</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">

    <link rel="stylesheet" href="../default/css/mui.min.css">
    <link rel="stylesheet" type="text/css" href="../default/css/index.css"/>
    <style type="text/css">
        .mui-content {
            background: #fff;
            min-height: 100%;
        }

        .mui-table-view:before {
            height: 0;
        }

        .mui-table-view:after {
            background-color: #F5F6F7;
        }

        .mui-table-view-cell:after {
            background-color: #F5F6F7;
        }

        .mui-table-view-cell {
            padding: 20px 10px;
        }

        .mui-input-row label {
            width: 45%;
        }

        .mui-input-row label ~ input, .mui-input-row label ~ select, .mui-input-row label ~ textarea {
            width: 55%;
        }

        .mui-input-group {
            font-size: 14px;
        }
        select {
            text-align: center;
            text-align-last: center;
        }
        .mui-input-row select{
            color: red;
        }
        .up-type{
            right: 10px;
        }
    </style>
</head>
<body>

<header class="mui-bar mui-bar-nav">
    <a class="mui-icon mui-icon-left-nav mui-pull-left backahter"></a>
    <h1 class="mui-title">提现</h1>
    <a class="'mui-btn mui-btn-link mui-pull-right backahter1" href="wirecord.html"><span>提现记录</span></a>
</header>

<div class="mui-content">
    <div class="mui-content-padded mui-text-center">
        <div class="wirecord-rule mui-text-left"><a href="exchange-rules.html">提现规则<i
                class="mui-icon mui-icon-help"></i></a></div>
        <div class="mui-row">
            <div class="mui-col-xs-4 mui-col-sm-4">
                <h5>佣金余额</h5>
                <h4 style="margin: 1.625rem auto;"><span id="commission">---</span></h4>
            </div>
            <div class="mui-col-xs-4 mui-col-sm-4">
                <h5>阅读宝数量</h5>
                <h4 style="margin: 1.625rem auto;"><span id="balance">---</span></h4>
            </div>
            <div class="mui-col-xs-4 mui-col-sm-4">
                <h5>本月直推会员人数</h5>
                <h4 style="margin: 1.625rem auto;"><span id="withdrawalLimit">---</span>人</h4>
            </div>
        </div>

        <form class="mui-input-group" id="input_example">
            <div class="mui-input-row">
                <label>选择提现方式</label>
                <select id="withdrawal-method">
                    <option value="">请选择</option>
                    <option value="阅读宝">阅读宝提现</option>
                    <option value="余额">余额提现</option>
                </select>
                <i class="up-type mui-icon mui-icon-arrowdown"></i>
            </div>
            <div class="mui-input-row">
                <label>支付宝姓名</label>
                <input type="text" class="mui-input-clear" name="alipayName" placeholder="请输入支付宝姓名" id="alipayName">
            </div>
            <div class="mui-input-row">
                <label>支付宝账号</label>
                <input type="text" class="mui-input-clear" placeholder="请输入支付宝账号" id="alipay" name="alipay">
            </div>
            <div class="mui-input-row" id="cashWithdrawalAmountss">
                <label id="tixian">提现余额</label>
                <input type="number" class="mui-input-clear" readonly  placeholder="请输入提现数量" id="cashWithdrawalAmount"
                       name="cashWithdrawalAmount" oninput="value=value.replace(/[^\d]/g,'')">
            </div>
            <div class="mui-input-row" id="cash" style="display: none">
                <label>换算金额</label>
                <input type="number" class="mui-input-clear" placeholder="" id="cashs" readonly>
            </div>
            <div class="mui-input-row">
                <label>实际到账金额</label>
                <input type="number" class="mui-input-clear" name="cashWithdrawalAmount1" id="cashWithdrawalAmount1"
                       placeholder="实际到账金额" readonly>
            </div>
            <div class="mui-input-row" style="line-height: 43px;">
                <p>温馨提示:每笔提现将会扣除3元的手续费</p>
            </div>
            <!-- <div class="mui-input-row">
                <label>密码</label>
                <input type="password" class="mui-input-password" placeholder="请输入密码">
            </div> -->
            <div class="mui-button-row">
                <button type="button" class="mui-btn mui-btn-primary" data-loading-text="提交中" id="gotosunbm">确认</button>
            </div>
        </form>
    </div>
    <div class="top-shadow"></div>
    <div class="mui-content-padded rule-description">
        <h4>提现说明</h4>
        <p>1.10个阅读宝等于1元</p>
        <p>2.提现款项提取到绑定支付宝账户</p>
        <p>3.提现到款时间为T+0</p>
        <p>4.工作时间：周一到周五的9点至5点30</p>
        <p>5.提现前请核对支付宝账号与支付宝姓名</p>
    </div>
    <div class="top-shadow"></div>
    <div class="mui-content-padded rule-description">

        <h4>联系客服</h4>
        <p>微信公众号: <b class="red">玩58新媒体吧</b></p>
    </div>
</div>

<script src="../default/js/jquery-2.14.js" type="text/javascript" charset="utf-8"></script>
<script src="../default/js/mui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../default/js/cookie.js"></script>
<script src="../default/js/code.js" type="text/javascript" charset="utf-8"></script>
<script src="../default/js/index.js" type="text/javascript" charset="utf-8"></script>
<script src="../default/js/public.js"></script>
<script>
    mui.init({
        swipeBack: true //启用右滑关闭功能
    });

    // ajax地址

    //用户余额
    var usercommission = 0;
    //本月直推人数
    var withdrawalLimit=0;
    // 用阅读宝
    var balance=0;
    // 用户vip
    var uservip='';
    document.getElementById("gotosunbm").addEventListener("tap", function () {
        //提现方式
        var withdrawalmethod = $("#withdrawal-method").val();
        // 姓名
        var alipayName = $("#alipayName").val();
        //支付宝账号
        var alipay = $("#alipay").val();
        // 提现金额
        var cashWithdrawalAmount = $("#cashWithdrawalAmount").val();
        // 实际到账金额
        var cashWithdrawalAmount1 = $("#cashWithdrawalAmount1").val();
        if(withdrawalmethod=='' || withdrawalmethod==null){
            mui.toast('请先选择提现方式');
            return false;
        }

        if(withdrawalmethod=='阅读宝'){

            if(cashWithdrawalAmount%10!=0){
                mui.toast('阅读宝提现只能为10的倍数');
                return false;
            }
        }
        if(Number(cashWithdrawalAmount1) < 7){
            mui.toast('最低提现10元');
            return false;
        }

        if (alipayName == "") {
            mui.toast('请输入支付宝姓名');
            return false;
        } else if (alipay == '') {
            mui.toast('请输入支付宝账号');
            return false;
        } else if (cashWithdrawalAmount == '') {
            mui.toast('请输入提现数量');
            return false;
        }/*else if (withdrawalmethod=='阅读宝' && parseInt(withdrawalLimit) < 3) {
            mui.toast('暂无阅读宝提现资格，请在直推会员人数界面查看详情!');
            return false;
        }*/else if (withdrawalmethod=='余额' && parseInt(usercommission) < parseInt(cashWithdrawalAmount)) {
            mui.toast('余额不足');
            return false;
        }else if (withdrawalmethod=='阅读宝' && balance < parseInt(cashWithdrawalAmount)) {
            mui.toast('阅读宝数量不足!');
            return false;
        }/*else if (withdrawalmethod=='阅读宝' && uservip!='是') {
            mui.toast('您不是会员，请成为会员后在来提现!');
            return false;
        }else if (withdrawalmethod=='余额' && uservip!='是') {
            mui.toast('您不是会员，请成为会员后在来提现!');
            return false;
        }*/else if (cashWithdrawalAmount < 10) {
            mui.toast('最低提现10元');
            return false;
        } else {
            // alert("金额:"+cashWithdrawalAmount);
            // alert("daozhang:"+cashWithdrawalAmount1);
            mui('#gotosunbm').button('loading');
            $.ajax({
                url: website + '/CashWithdrawalController/addCashWithdrawal',
                type: 'post',
                data: {
                    'userId': userId,
                    'alipayName': alipayName,
                    'alipay': alipay,
                    'cashWithdrawalAmount': cashWithdrawalAmount,
                    'cashWithdrawalAmount1': cashWithdrawalAmount1,
                    'withdrawals':withdrawalmethod
                },
                success: function (data) {
                    mui.toast(data.msg);
                    if(data.msg=='申请成功'){
                        location.reload()
                    }
                    mui('#gotosunbm').button('reset');

                }, error: function () {
                    mui.showLoading("发生错误,返回首页..", "div");
                    mui.openWindow({
                        url: "http://newst.whilte.com/index.html",
                    });
                }
            });


        }
    });

    $(function () {
        findByUserBalance();
        queryQuota();
        areMembers();
    });

    // 判断用户是否为会员
    function areMembers() {
        $.ajax({
            url:website+'/UserController/areMembers',
            type:'post',
            data:{
                userId : userId
            },
            success:function (data) {
                uservip=data.data
            }
        });
    }

    $("#withdrawal-method").on('input propertychange', function () {
        var withdrawalmethod = $("#withdrawal-method").val();           //提现方式

        if(withdrawalmethod=="阅读宝" || withdrawalmethod=="余额"){
            $("#cashWithdrawalAmount").attr('readonly',false);
        }else{
            $("#cashWithdrawalAmount").attr('readonly',true);
        }

        var withdrawalmethod = $("#withdrawal-method").val();           //提现方式
        var cashWithdrawalAmount = $("#cashWithdrawalAmount").val();    //用户输入金额

        if(withdrawalmethod=="阅读宝"){
            $("#tixian").html("提现数量");
            $("#cash").attr("style","display:block;");//显示div
            var cashWithdrawalAmounts =cashWithdrawalAmount/10;
            $("#cashs").val(cashWithdrawalAmounts);
            $("#cashWithdrawalAmount1").val(cashWithdrawalAmounts-3);
            var cashWithdrawalAmount1 = $("#cashWithdrawalAmount1").val();

            if (cashWithdrawalAmount1 >= 0) {       //先减少再做的判断所以是以减少之后的值 来做判断
                $("#cashWithdrawalAmount1").val(cashWithdrawalAmount1);
            } else {
                $("#cashWithdrawalAmount1").val('0');
            }
        }else{          //选择余额提现时
            $("#tixian").html("提现余额");
            $("#cash").attr("style","display:none;");//隐藏div
            $("#cashWithdrawalAmount1").val(cashWithdrawalAmount-3);
            var cashWithdrawalAmount1 = $("#cashWithdrawalAmount1").val();
            if (cashWithdrawalAmount1 >= 0) {       //先减少再做的判断所以是以减少之后的值 来做判断
                $("#cashWithdrawalAmount1").val(cashWithdrawalAmount1);
            } else {
                $("#cashWithdrawalAmount1").val('0');
            }
        }

    });



    $("#cashWithdrawalAmountss").on('click','input', function () {
        var withdrawalmethod = $("#withdrawal-method").val();           //提现方式

        if(withdrawalmethod=="" || withdrawalmethod==null){
            mui.toast('请选择提现方式');
        }
    });


    $("#cashWithdrawalAmount").on('input propertychange', function () {

        var withdrawalmethod = $("#withdrawal-method").val();           //提现方式
        var cashWithdrawalAmount = $("#cashWithdrawalAmount").val();    //用户输入金额

        if(withdrawalmethod=="阅读宝"){
            cashWithdrawalAmount =cashWithdrawalAmount/10;
            $("#cashs").val(cashWithdrawalAmount);
            $("#cashWithdrawalAmount1").val(cashWithdrawalAmount-3);
           var cashWithdrawalAmount1 = $("#cashWithdrawalAmount1").val();

            if (cashWithdrawalAmount1 >= 0) {       //先减少再做的判断所以是以减少之后的值 来做判断
                $("#cashWithdrawalAmount1").val(cashWithdrawalAmount1);
            } else {
                $("#cashWithdrawalAmount1").val('0');
            }
        }else {

        var result = $(this).val() - 3;
        if (result >= 0) {
            $("#cashWithdrawalAmount1").val(result);
        } else {
            $("#cashWithdrawalAmount1").val('0');
        }

        }
    });


    // 查询用户的分销佣金和阅读宝,和朋友
    function findByUserBalance() {
        // 查询用户的阅读宝和余额
        $.ajax({
            url: website + '/UserController/findByUserBalance ',
            type: 'post',
            data: {userId: userId},
            success: function (data) {
                console.log(data);
                $("#commission").html(data.data.commission);
                $("#balance").html(data.data.balance);
                balance=data.data.balance;
                usercommission = data.data.commission;
            }, error: function () {
                mui.showLoading("发生错误,返回首页..", "div");
                mui.openWindow({
                    url: "http://newst.whilte.com/index.html",
                });
            }
        });

    };


    // 查询用户阅读宝提现额度
    function queryQuota() {
        // 查询用户本月直推人数
        $.ajax({
            url: website + '/UserController/queryDirectPush',
            type: 'post',
            data: {userId: userId},
            success: function (data) {
                $("#withdrawalLimit").html(data.data);
                withdrawalLimit=data.data
                // withdrawalLimit=2
            }, error: function () {
                mui.showLoading("发生错误,返回首页..", "div");
                mui.openWindow({
                    url: "http://newst.whilte.com/index.html",
                });
            }
        });

    };


    mui('header').on('tap', '.backahter', function (e) {
        mui.openWindow({
            url: 'wallet.html'
        });
    });
    mui('header').on('tap', '.backahter1', function (e) {
        mui.openWindow({
            url: 'wirecord.html'
        });
    });



</script>
</body>
</html>
